﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script type="text/javascript" src="js/WdatePicker.js"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
var myStreets = [];

function sfDistrictChange() {
	var district = $("#sf_district").val();
	
	if (district == "0") {
		$("#sf_street").html("<option value='0'>选择街道</option>");
	} else {
		$("#sf_street").html("<option value='0'>全  部</option>" + initStreet(district));
		$("#sf_street").val("0");
	}
	$("#sf_community").html("<option value='0'>选择社区</option>");
}

function sfStreetChange() {
	var sid = $("#sf_street").val();
	
	if ((sid == null) || (sid.length == 1)) {
		$("#sf_community").html("<option value='0'>选择社区</option>");
	} else {
		$("#sf_community").html("<option value='0'>全  部</option>" + initCommunity(sid));
	}
}

function loadStreetCommunity() {
	$.get('base?action=12',function (data, textStatus){
		$.extend(true, myStreets, data);
	});
}

function initStreet(district) {
	var ops = "";
	for (i = 0; i < myStreets.length; i++) {
		if (myStreets[i].district != district)
			continue;
		ops += "<option value='" + myStreets[i].sid + "'>" + myStreets[i].sid + "|" + myStreets[i].sname + "</option>";
	}
	return ops;
}

function initCommunity(sid) {
	var ops = "";
	for (var i = 0; i < myStreets.length; i++) {
		if (myStreets[i].sid != sid) 
			continue;
		var cs = myStreets[i].communitys;
		
		for (var j = 0; j < cs.length; j++) {
			ops += "<option value='" + cs[j].cid + "'>" + cs[j].cid + "|" + cs[j].cname + "</option>";
		}
	}

	//$("#commuid").html(ops);
	return ops;
}

function searchFlow() {
	var company = $("#sf_company").val();
	var wname = $.trim($("#sf_wname").val());
	var sdate = $.trim($("#sf_startdate").val());
	var edate = $.trim($("#sf_enddate").val());
	var cid   = $.trim($("#sf_cid").val());
	var cname = $.trim($("#sf_cname").val());
	var district = $.trim($("#sf_district").val());
	var street = $.trim($("#sf_street").val());
	var community = $.trim($("#sf_community").val());
	var ctype = $("#sf_ctype").val();
	
	if ((sdate.length + edate.length) == 8) {
		alert("必须同时选择起始时间和结束时间！");
		return;
	}
  var q = "action=7&oper=sum&comid=" + company + "&wname=" + escape(wname) + "&cid=<" + cid + ">&cname=" + escape(cname);
  q += "&district=" + district + "&sid=" + street + "&commuid=" + community + "&ctype=" + ctype;
	if ((sdate.length == 8) && (edate.length == 8))
		q += "&recdate=[" + sdate + "," + edate + "]";
	if (this.id == "sf_submit")
		jQuery("#list1").jqGrid('setGridParam',{page:1,url:"main?" + q}).trigger("reloadGrid");
	else
		$("#df").attr("src","main?oper=sumexcel&" + q);
};

function initCompany() {
	$.get('main?action=14',function (data, textStatus) {
		var ops = data;
		var len = ops.length;
		$("#sf_company").html("<option value='0'>全  部</option>" + ops.substring(8, len - 9));
	});
};

function setGrid() {
	jQuery("#list1").jqGrid({
			url:'main?action=7&oper=sum',
			datatype: "json",
			hidegrid: "false",
			colNames:['客户编号','客户姓名','客户类型','服务次数','所属区','账户消费','现金消费','街道','社区','地址','联系电话'], 
			colModel:[ 
					{name:'cid', width:100, sortable:false,align:"right"},
					{name:'cname', width:50, sortable:false, align:"right"},
					{name:'ctype',width:60, sortable:false, align:"right",formatter:'select', editoptions:{value:"1:三无老人;2:70岁低保;3:85岁高龄;4:70岁优抚;5:70岁劳模"}},
					{name:'servnum', width:100, sortable:false, align:"right"},
					{name:'district',width:50, sortable:false, align:"right",formatter:'select',editoptions:{value:"1:市辖区;2:桥东区;3:桥西区;4:高新区;5:宣化区;6:下花园区"}},
					{name:'consume', width:120, sortable:false, align:"right"},
					{name:'cash', width:120, sortable:false, align:"right"},
					{name:'sid',width:120, sortable:false, align:'right'},
					{name:'commuid',width:120, sortable:false, align:'right'},
					{name:'caddress',width:180, sortable:false, align:'right'},
					{name:'cmobile',width:180, sortable:false, align:'right'}
			], 
			viewrecords: true,
			rowNum:20,
			pager: '#gridpager',
			footerrow: true,
			userDataOnFooter: true,
			height: 450,
			caption:"查询汇总"
	})};
	
	$(document).ready(function(){
		setGrid();
		loadStreetCommunity();
		initCompany();
		$("#sf_submit").click(searchFlow);
		$("#sf_excel").click(searchFlow);
		$("#sf_district").val("0");
		$("#sf_street").live('change', sfStreetChange);
	});
</script>

<body style="background-color:#4e84c0;">
									<iframe id="df"  name="df" src="" width=0 height=0 frameborder="0" ></iframe>
                	<form id="sf" action="main">
                	<table>
                	<tr>
                		<td>起始日期<input id="sf_startdate" name="sf_recdate" type="text" text="" size=10 onClick="WdatePicker({dateFmt:'yyyyMMdd'})" /></td>
                		<td>所 属 区<select id="sf_district" name="sf_district" onChange="sfDistrictChange()">
			                		<option value="0">全  市</option>
			                		<option value="1">市辖区</option>
		                			<option value="2">桥东区</option>
		                			<option value="3">桥西区</option>
		                			<option value="4">高新区</option>
		                			<option value="5">宣化区</option>
		                			<option value="6">下花园区</option>
			                		</select></td>
	                	<td>办 事 处<select id="sf_street" name="sf_street">
                								<option value='0'>选择街道</option>
                						 </select></td>
	                	<td>居 委 会</td><td><select id="sf_community" name="sf_community">
                						<option value='0'>选择社区</option>
                				 </select></td>
                		<td>人员类型<select id="sf_ctype" name="sf_ctype">
                								<option value="0">全  部</option>
																<option value="1">三无老人</option>
																<option value="2">70岁低保</option>
																<option value="3">85岁高龄</option>
																<option value="4">70岁优抚</option>
			                					<option value="5">70岁劳模</option>
                				</select></td>
                		<td><input type="button" id="sf_submit" value="查 询"></td>
                	</tr>
                	<tr>
                		<td>结束日期<input id="sf_enddate" name="sf_enddate" type="text" text="" size=10 onClick="WdatePicker({dateFmt:'yyyyMMdd'})" /></td>
                		<td>服务公司<select id="sf_company" name="sf_company"><option value='0'>全  部</option></select></td>
                		<td>服务人员<input type="text" id="sf_wname" name="sf_wname" size="10"/></td>
                		<td>客户编号(*)</td><td><input id="sf_cid" name="sf_cid" type="text" text=""  size="15"/></td>
                		<td>客户姓名<input id="sf_cname" name="sf_cname" type="text" text="" size="10"/></td>
                		<td><input type="button" id="sf_excel" value="导 出"></td>
                	</tr>
                	</table>
                	</form>
         
				<div id="RightPane">
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager"></div>
					</div>
				</div>


</body>
